<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sidebar{

	private $konten;

	public function __construct(){
		$this->CI =& get_instance();
	}

	public function is_set(){
		if(isset($this->konten)) 
			return true;
		else return false;
	}

	public function create_menu($links = array()){

		$menu = '';

		foreach($links as $fungsi => $label){

			$base = base_url();
			$kelas = $this->CI->uri->segment(1);
			$id = $this->CI->uri->segment(3);

			$menu .= "<a href='$base$kelas/$fungsi/$id'";

			if($this->CI->uri->segment(2) == $fungsi) 
				$menu .= 'class = "active"';
			else if($this->CI->uri->segment(2) == '' && $fungsi == 'index')
				$menu .= 'class = "active"';

			$menu .= ">$label</a>";
		}

		$this->konten[] = "<div id='sidebar_menu'>$menu</div>";

		return $this;
	}

	public function create_identitas($akun){

		if(get_class($akun) == 'models\Speedy')
			$id = $akun->get_id();
		else $id = $akun->get_username();

		if(get_class($akun) == 'models\Perusahaan')
			$img = img('images/pabrik.png');
		else $img = img('images/orang.png');
		$nama = heading($akun->get_nama(),3);

		$this->konten[] = "<div id='identitas'>$img $nama <p>ID: $id</p></div>";

		return $this;
	}

	public function create_error(){

		$header = heading('Error!',3);

		$this->konten[] = 
			"<div class='block' id='error_info' style='display: none'>
				$header 
				<div></div> 
			</div>";

		return $this;
	}

	public function create_custom($tag,$isi,$id = '' ,$tambahan = ''){

		$this->konten[] = "<$tag $id $tambahan> $isi </$tag>";

		return $this;
	}

	public function add_custom($tag,$isi,$id = '' ,$tambahan = ''){

		$this->konten[] = "<$tag $id $tambahan> $isi </$tag>";

		return $this;
	}

	public function add_calendar($calendar){
		$this->konten[] = "<div class='calendar'> $calendar </div>";
		return $this;
	}

	public function __toString(){

		$string = "<div id='sideBar'>";

		foreach($this->konten as $konten){
			$string .= $konten;
		} 

		$string .= "</div>";

		return $string;
	}

}
